layui.use(['form', 'jquery', 'layer', 'table', 'laydate', 'laypage', 'upload'], function() {
	var form = layui.form;
	var $ = layui.$;
	var table = layui.table;
	var layer = layui.layer;
	var laydate = layui.laydate;
	var laypage = layui.laypage;
	var upload = layui.upload;
	// 关闭页面
	$('#close_page').on('click', function() {
		parent.layer.closeAll('iframe');
	})
	var table_filter = 'invoice_detail_list';
	// 渲染表格
	table.render({
		elem: '#' + table_filter,
		id: table_filter,
		url: ajax_detail_url,
		method: 'post',
		where: {
			_o: 'invoice_id',
			_b: 'desc',
			cart_id:cart_id.split(',')
		},
		cols: [cols_detail]
	});

	// 上传发票凭证
	var upload_invoice = upload.render({
		elem: '.up_invoice',
		url: upload_uri,
		accept: 'file',
		acceptMime: 'image/*,application/pdf',
		exts: 'jpg|png|gif|bmp|jpeg|pdf',
		choose: function() {
			layer.load(1);
		},
		done: function(res) {
			var html = '<span class="invoice-link">' +
				'<a href="' + res.data.save_path + '" style="color: #ffffff;" target="_blank">' +
				'<i class = "layui-icon layui-icon-link" ></i>查看发票</a > '+
			'</span>';
			$('input[name="invoice_proof"]').val(res.data.upload_id);
			$('.up_invoice').after(html);
			layer.closeAll('loading');
		},
		error: function() {
			layer.closeAll('loading');
			layer.msg('上传错误', {
				icon: 2,
				anim: 6
			});
			return false;
		}
	});
	// 确认开票
	form.on('submit(submit_invoice)', function(data) {
		var field = {
			invoice_id:invoice_id,
			invoice_proof:$('input[name="invoice_proof"]').val()
		}
		if(field.invoice_proof == ''){
			layer.msg('请上传发票凭证',{icon:2,anim:6});
			return false;
		}
		layer.confirm('确认要开具发票吗？', {
			icon: 3,
			title: '确认开票'
		}, function(index) {
			send_info(save_alone_invoice_url, field, function(data) {
				//layer.closeAll();
				parent.layui.table.reload('invoice_finance_list');
				parent.layer.msg('发票开具成功', {
					icon: 1,
					anim: 6
				});
				parent.layer.closeAll('iframe');
			})
		})
	})

})
